package com.songcha.library_common.ui.view.compose

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp


@Composable
fun ComposeProgressBarView(modifier: Modifier, width:Float, height:Float,
                                   bgColor: Color, valueBgColor: Color, percent:Float){
    var p = percent
    if(p < 0) p = 0f
    else if(p > 100) p = 100f
    val valueWidth = (width * p / 100)

    Box(modifier = Modifier.then(modifier)
        .size(width.dp,height.dp)
        .clip(RoundedCornerShape((height / 2).dp))
        .background(bgColor)
    ){
        Box(modifier = Modifier
            .fillMaxHeight()
            .width(valueWidth.dp)
            .clip(RoundedCornerShape((height / 2).dp))
            .background(valueBgColor)
        )

    }

}